﻿using Pdoxcl2Sharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using V3MainTool.Model;

namespace V3MainTool.UI
{
    /// <summary>
    /// UCBuildingGroups.xaml 的交互逻辑
    /// </summary>
    public partial class UCBuildingGroups : UserControl
    {
        string fold;
        BuildingGroupsFamily family = new BuildingGroupsFamily();
        List<string> fileList = new List<string>();
        public UCBuildingGroups()
        {
            InitializeComponent();
        }
      
        private void btnOpenFold_Click(object sender, RoutedEventArgs e)
        {
            fold = MainWindow.Instance.GetFold();
            System.Diagnostics.Process.Start("explorer.exe", fold + @"\common\building_groups\");
        }

        private void btnReload_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                fold = MainWindow.Instance.GetFold();
                string mypath = fold + @"\common\building_groups\00_building_groups.txt";
                LocalHelper.Buildings = LocalHelper.GetDic(fold + @"\localization\simp_chinese\buildings_l_simp_chinese.yml");
                LocalHelper.Interfaces = LocalHelper.GetDic(fold + @"\localization\simp_chinese\interfaces_l_simp_chinese.yml");

                using (FileStream fs = new FileStream(mypath, FileMode.Open))
                {
                    family = ParadoxParser.Parse(fs, new BuildingGroupsFamily());
                }
                dgv.ItemsSource = family.MyList;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
    }
}
